<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}
$gid=intval($_GET["gid"]);
$relatecatid=intval($_GET["relatecatid"]);
if(empty($gid)){
    echo "<div class=\"pageHeader\">没有选择产品，请关闭窗口。</div>";
    exit; 
}

$page = !($_POST['pageNum'])?'1':intval($_POST['pageNum']);
$pagesize= !($_POST['numPerPage'])?'20':intval($_POST['numPerPage']);


if(empty($pagesize)){
    $pagesize=20;
}
$frmnum=($page-1)*$pagesize;
$orderField=trim($_POST["orderField"]);
$orderDirection=trim($_POST["orderDirection"]);
if(empty($orderField)){
    $orderField="id";
}
if(empty($orderDirection)){
    $orderDirection="desc";
}
if($orderField<>""){
    $order=" order by $orderField ".$orderDirection;
}else{
    $order=" order by t.id desc";
}

$q=trim($_POST['q']);

$catlistrow=$ezhand->select_all("category",'id,catname','parentid=62');

$ralategname=$ezhand->select('thread',"title",'id="'.$gid.'"');  
$where="";
if(!empty($relatecatid)){
    $where.=" and r.relatecatid=".$relatecatid;
}

$total=$ezhand->count("thread t,category c,goods_relate r","t.catid=c.id and t.id=r.relateid and r.gid=".$gid." and  t.title like '%$q%'".$where);
$row=$ezhand->select_all("thread t,category c,goods_relate r",'t.*,c.catname,r.relatecatid,r.id as rid','t.catid=c.id  and t.id=r.relateid and r.gid='.$gid.' and t.title like "%'.$q.'%"'.$where.' '.$order.' limit '.$frmnum.','.$pagesize);



?>